package org.anti996.lms.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BookingOutput {
    private Booking booking;

    private Transport transport;  // ? no need

    // Customer From
    private Customer cFrom;

    // Customer To
    private Customer cTo;

    // Warehouse From
    private Warehouse wFrom;

    // Warehouse To
    private Warehouse wTo;

    // Operator From
    private Operator oFrom;

    // Operator To
    private Operator oTo;

    private BookingStatus status;

    public static BookingStatus calculateStatus(BookingOutput output) {
        if (output.transport == null) {
            return BookingStatus.WAREHOUSE;
        } else {
            // TODO 怎么计算这四个状态啊！！！
            // 我只有一个t_num，想知道对应运单那两个时间填了没，这时候又得查数据库  1
            // 而且我就显示一个订单信息，不需要知道对应c,w,o的所有信息（别连密码也给发了鸭）   2
            // 1 解决：在数据库booking加几个计算缓存属性：货单状态（enum类型）、付款金额，并用触发器进行计算
            // 2 解决：更改Mapper文件，和SQL语句，只取出需要的属性，其他的不需要的都是null
            if (output.booking.getCheckOut() != null) {
                return BookingStatus.FINISHED;
            } else if (output.transport.getArrive() != null) {
                return BookingStatus.WAITING;
            } else if (output.transport.getDepart() != null) {
                return BookingStatus.TRANSPORT;
            } else {
                return BookingStatus.WAREHOUSE;
            }
        }
    }
}
